

from dataclasses import dataclass, field
from datetime import datetime

from sqlalchemy import *

from server import mapper_registry


# class Testcase(db.Model):
#     '''
#     测试用例表
#     '''
#
#     __tablename__ = 'testcase'
#
#     id = db.Column(db.Integer, primary_key=True, autoincrement=True)
#
#     uid = db.Column(db.String(255))
#
#     name = db.Column(db.String(255))
#
#     runner_id = db.Column(db.Integer, ForeignKey('runner.id'))
#
#     data = db.Column(db.String(255))
#
#     create_time = db.Column(db.DateTime, default=datetime.datetime.now(), comment="创建时间")
#
#     update_time = db.Column(db.DateTime, default=datetime.datetime.now(), comment="更新时间")
#
#     def as_dict(self):
#         return {
#             "id": self.id, "uid": self.uid, "name": self.name,
#             "runner_id": self.runner_id, "data": self.data,
#             "create_time": self.create_time, "update_time": self.update_time
#         }
#


@mapper_registry.mapped
@dataclass
class Testcase:
    __tablename__ = 'testcase'
    __sa_dataclass_metadata_key__ = "sa"

    id: int = field(default=None, metadata={"sa": Column(Integer, primary_key=True)}, )
    uid: str = field(default=None, metadata={"sa": Column(String(255))}, )
    name: str = field(default=None, metadata={"sa": Column(String(255))}, )
    runner_id: int = field(default=None, metadata={"sa": Column(Integer, ForeignKey('runner.id')),})
    data: str = field(default=None, metadata={"sa": Column(String(255))}, )
    create_time: datetime = field(init=False, metadata={"sa": Column(DateTime, nullable=True, default=datetime.now)}, )
    update_time: datetime = field(init=False, metadata={"sa": Column(DateTime, nullable=True, default=datetime.now, onupdate=datetime.now)}, )
